import {
    reqgoodslist,
    reqgoodsinfo,
    reqgoodsadd,
    reqgoodscount
} from "../../request/api.js"
const state = {
    info: {
        isshow: false,
        isadd: true
    },
    page: {
        size: 3,
        page: 1
    },
    goodslist: [],
    goodsinfo: [],
    goodscount: 0,
}
const getters = {
    page(state) {
        return state.page
    },
    info(state) {
        return state.info
    },
    goodslist(state) {
        return state.goodslist
    },
    goodsinfo(state) {
        return state.goodsinfo
    },
    goodscount(state) {
        return state.goodscount
    },
}
const mutations = {
    changepage(state, data) {
        state.page.page = data
    },
    changeinfo(state, data) {
        state.info = data
    },
    goodslist(state, data) {
        state.goodslist = data
    },
    goodsinfo(state, data) {
        state.goodsinfo = data
    },
    goodscount(state, data) {
        state.goodscount = data
    },

}
const actions = {
    changepage(context,data){
        context.commit("changepage",data)
        reqgoodslist(context.state.page).then(res => {
            context.commit("goodslist", res.data.list)
        })
    },
    goodscount(context){
        reqgoodscount().then(res => {
            context.commit("goodscount", res.data.list[0].total)
        })
    },
    goodslist(context) {
        reqgoodslist(context.state.page).then(res => {
            context.commit("goodslist", res.data.list)
        })
    },
    goodsinfo(context, data) {
        reqgoodsinfo(data).then(res => {
            res.data.list.id = data.id
            context.commit("goodsinfo", res.data.list)
        })
    },
    goodsadd(context, data){
        reqgoodsadd().then(res=>{})
    },
}
export default {
    state,
    getters,
    mutations,
    actions,
    namespaced: true
}